package info.motteke.util;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;

public abstract class SecureProperties {

    private final Properties prop = new Properties();

    protected final Picker NORMAL = new NormalPicker(prop);

    protected final Picker ENCRYPT = new CryptPicker(prop);

    private final Map<String, Picker> pickers;

    protected abstract Map<String, Picker> initKeys();

    protected SecureProperties() {
        pickers = Collections.unmodifiableMap(initKeys());
    }

    public void load(Reader reader) throws IOException {
        prop.load(reader);
    }

    public void store(Writer writer) throws IOException {
        prop.store(writer, "");
    }

    protected String get(String key) {
        return pickers.get(key).get(key);
    }

    protected void set(String key, String value) {
        pickers.get(key).set(key, value);
    }
}
